home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / CASE.ASM next >
Assembly Source File  |  1986-12-13  |  2KB  |  49 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. ****************************************************************
  12. * CASE - Case statement executor
  13. *
  14. *    ENTRY:    A0 contains address of case table
  15. *        D0 contains case selector value
  16. *
  17. *    Case Table:
  18. *        dc.w    number of valid options
  19. *        dc.w    first match value
  20. *        dc.l    address of first case arm
  21. *        dc.w    second match value
  22. *        dc.l    address of second case arm
  23. *        . . .
  24. *        dc.w    n'th match value
  25. *        dc.l    address of n'th case arm
  26. *        dc.l    default (no match) arm
  27. *
  28. *    EXIT:    A0 is undefined.
  29. *        D0 retains case selector value.
  30. *
  31.     .xdef    case
  32. case:
  33.     move.l    d1,-(a7)    * save caller's D1
  34.     move.w    (a0)+,d1    * get case value count
  35.     subq.w    #1,d1        * adjust count value
  36. loop:
  37.     cmp.w    (a0)+,d0    * Check against match value
  38.     beq    done        * found it.
  39.     addq.l    #4,a0        * move past useless case arm
  40.     dbra    d1,loop        * try again
  41. done:
  42.     move.l    (a7)+,d1    * restore caller's d1
  43.     move.l    (a0),a0        * get jump address
  44.     jmp    (A0)        * go execute case arm. 
  45. *
  46. *** Note: return from case arm is to statement following ********
  47. *** the call to this routine ************************************
  48.